package locutor.draft.dg;
// locutor
// (c) 2008-2009, Normen Müller, normen.mueller@gmail.com  
// $Id: DG.scala 228 2009-09-15 11:09:26Z nmueller $
//package info.kwarc.locutor.dg
//
//import collection._
//
//import scaup.xml.xpath._
//import scaup.xml.xpath.{LocationPath => XPath}
//
//abstract class INFOM
//abstract class Type
//abstract class Dependency
//
//class DG {
//  private val nodes: mutable.Map[XPath,INFOM] = mutable.Map()
//  private val edges: mutable.Map[Type,Dependency] = mutable.Map()
//  
//  /** Get the node identified by XPath expression <code>p</code>
//   */
//  def \(p: XPath): Set[INFOM] = p match {
//    case Ʈ(*) => Set.empty[INFOM] ++ nodes.values
//    case _    => nodes.get(p) match {
//      case Some(v) => Set(v)
//      case None    => Set.empty[INFOM]
//    }
//  }
//}    
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////    
//package module.dg
//
//import java.net.URI
//import java.io.File
//import java.text.MessageFormat.{format}
//
//import scaup.Views._
//import scaup.data._
//import scaup.io.FileType._
//import scaup.util.parsing.dot._
//
//case class DGWarning(message: String) extends Throwable(message)
//case class DGError(message: String) extends Throwable(message)
//
///**
// * @author <a href="mailto:normen.mueller@googlemail.com">Normen M&#xFC;ller</a>
// * @version 0.0.5 */
//object DG {
//  def apply(f: File) = new DG(f)
//  def unapply(g: DG) = g.graph
//}
//
///** 
// * @author <a href="mailto:normen.mueller@googlemail.com">Normen M&#xFC;ller</a>
// * @version 0.0.5 */
//class DG @throws(classOf[DGError]) @throws(classOf[DGWarning]) (root: File) {
//  if(root == null || !root.exists)
//    throw DGError(format("Physical root path may not be null."))
//  
//  private val graph: Graph = Graph(false,true,Some(root.p),
//                                   ((fs: List[File]) => fs match {
//                                     case hd::tl => parse(hd) ::: parse(tl)
//                                     case _ => Nil
//                                   })(root.ls remove (_.p endsWith ".dep")):_*)
//  
//  private def parse(f: File): List[Statement] = f.t match {
//    case DIRECTORY => Edge(Nil,Node(f.p),Node(f.pp)) :: Subgraph(Some(f.p), parse(f.ls remove (_.p endsWith ".dep")):_*) :: Nil
//    case FILE if (f.p+".dep").toFile exists => DOT.parse((f.p+".dep").toFile) match {
//      case Some(g) => Subgraph(Some(f.p),adapt(f,g.statements):_*) :: Nil
//      case _ => Edge(Nil,Node(f.p), Node(f.pp)) :: Nil 
//    }      
//    case FILE => Edge(Nil,Node(f.p), Node(f.pp)) :: Nil
//    case SYMLINK => throw DGWarning(format("DG parse warning: Symbolic links are not yet supported (''{0}'')",f.p))
//    case z@_ => throw DGError(format("DG parse error: Unkown file type (''{0}'')",f.p))
//  }
//  private def parse(fs: List[File]): List[Statement] = fs flatMap (parse(_))
//  
//  //@todo implement; depends on XPath parser implementation!
//  private def adapt(f: File, s: Statement): Statement = s match {
//    case Subgraph(id,ss@_*) => s
//    case Node(id,as@_*) =>
//      //val scope = Path("file:///Users/nmueller/tmp/test.txt.dep".toURI, "./[1]/[2]".toXPath)
//      //println(scope)
//      //Node(scope/(as\"path"),(as ++ List(Attr("orgid",Some(id)))):_*)
//      s
//    case Edge(as,ns@_*) => s
//    case Attr(n,v) => s
//    case Attrs(k,as@_*) => s
//  }
//  private def adapt(f: File, s: Seq[Statement]): Seq[Statement] = s map (adapt(f, _))
//  
//  override def toString = graph.toString()
//}
//
//import scaup.xml.xpath._
//import scaup.xml.xpath.{Expr => XPath}
//
//case class Path(uri: URI, xp: XPath) { override def toString = uri + "@" + xp }
//
//case class URL(path: XPath) extends Attr("URL", Some(path.toString))
